package br.com.localfloripa.scheduling;

import java.io.File;
import java.util.Calendar;
import java.util.ResourceBundle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component("garbageCollectorWorker")
public class GarbageCollectorWorker implements Worker {
	
	public static final Logger log = LoggerFactory.getLogger(GarbageCollectorWorker.class);

	public GarbageCollectorWorker() {
		super();		
	}

	@Async
	@Override
	public void periodicalWork() throws Exception {
			
	}

	@Async
	@Override
	public void dailyWork() throws Exception {		
		/** Limpa diretórios temporários no servidor **/
		log.info("GARBAGE COLLECTOR - "+Calendar.getInstance().getTime());
		ResourceBundle resource = ResourceBundle.getBundle("messages.MessageResources");
		File dir = new File(resource.getString("path.files.base.tmp"));
		File[] files = dir.listFiles();
		if (files.length > 0) {
			for (File file : files) {
				if (file.exists())
					file.delete();
			}
		}	
	}

	@Override
	public void weeklyWork() throws Exception {
		// TODO Auto-generated method stub

	}

}
